#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi


#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > rsp_twophot.info <<'%EOF%'
   rsp_twophot
   -----------
   Molecule:         KUM1
   Wave Function:    SCF / 3-21G
   Test Purpose:     Two-photon absorption
%EOF%

#######################################################################
#  MOLECULE INPUT
#######################################################################
cat > rsp_twophot.mol <<'%EOF%'
BASIS
3-21G
Two-photon absorption

    2    3  X  Y  Z1
      6.0    4
 C1    0.6289236   0.0000000   0.0000000
 C2    1.9404215   0.0000000   0.0000000
 C3    2.8397340   1.1742575   0.0000000
 C4    4.1286140   0.7285165   0.0000000
      1.0    2
 H1    2.4725314   2.1982533   0.0000000
 H2    5.0413894   1.3219498   0.0000000
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > rsp_twophot.dal <<'%EOF%'
**DALTON INPUT
.RUN RESPONSE
**INTEGRALS
.DIPLEN
**WAVE FUNCTION
.HF
**RESPONSE
*QUADRATIC
.SINGLE
.TWO-PHOTON
.ROOTS
5 0 0 0 0 0 0 0
**END OF DALTON INPUT
%EOF%
#######################################################################



#######################################################################

#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >rsp_twophot.check
cat >>rsp_twophot.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

# Integral setup
CRIT1a=`$GREP "Calculation of one\- and two\-electron Hamiltonian integrals\." $log | wc -l`
CRIT1b=`$GREP "Calculation of one\-electron Hamiltonian integrals\." $log | wc -l`
CRIT2=`$GREP "The following one\-electron property integrals are calculated" $log | wc -l`
CRIT3=`$GREP "\- overlap integrals" $log | wc -l`
CRIT4=`$GREP "\- dipole length integrals" $log | wc -l`
TEST[1]=`expr	$CRIT1a \+ $CRIT1b \+ $CRIT2 \+ $CRIT3 \+ $CRIT4`
CTRL[1]=4
ERROR[1]="INTEGRAL CALCULATION NOT SET UP CORRECTLY"

# Basis set
CRIT1=`$GREP "Basis set used is \"3\-21G\" from the basis set library\." $log | wc -l`
CRIT2=`$GREP "C * 12 * 6\.0000 * 15 * 9 * \[6s3p\|3s2p\]" $log | wc -l`
CRIT4=`$GREP "H * 8 * 1\.0000 * 3 * 2 * \[3s\|2s\]" $log | wc -l`
CRIT5=`$GREP "total\: * 20 * 80\.0000 * 204 * 124" $log | wc -l`
TEST[2]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT4 \+ $CRIT5`
CTRL[2]=4
ERROR[2]="BASIS SET NOT READ CORRECTLY"


# Symmetry
CRIT1=`$GREP "Number of coordinates in each symmetry\: * 10 * 10 * 10 * 10 * 6 * 6 * 4 * 4" $log | wc -l`
CRIT2=`$GREP "Number of orbitals in each symmetry\: * 28 * 28 * 22 * 22 * 8 * 8 * 4 * 4" $log | wc -l`
TEST[4]=`expr	$CRIT1 \+ $CRIT2`
CTRL[4]=2
ERROR[4]="SYMMETRY NOT CORRECT"

# Energy
CRIT1=`$GREP "Final * HF energy\: * \-456\.3410910(7|8)." $log | wc -l`
TEST[5]=`expr   $CRIT1`
CTRL[5]=1
ERROR[5]="FINAL HF ENERGY NOT CORRECT"

# Response calculation
CRIT1=`$GREP "Quadratic Response single residue calculation" $log | wc -l`
CRIT2=`$GREP "Two\-photon transition processes computed" $log | wc -l`
CRIT3=`$GREP "Spin of operator A \, ISPINA\= * 0" $log | wc -l`
CRIT4=`$GREP "Spin of operator B \, ISPINB\= * 0" $log | wc -l`
CRIT5=`$GREP "Spin of operator C \, \(Excitation energy\) ISPINC\= * 0" $log | wc -l`
CRIT7=`$GREP "1 A OPERATORS OF SYMMETRY NO\: * (2|3|5) AND LABELS\:" $log | wc -l`
CRIT8=`$GREP "1 B OPERATORS OF SYMMETRY NO\: * (2|3|5) AND LABELS\:" $log | wc -l`
TEST[6]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ \
		$CRIT7 \+ $CRIT8`
CTRL[6]=11
ERROR[6]="RESPONSE CALCULATION NOT SET UP CORRECTLY"

# Two-photon transition tensor
CRIT1=`$GREP "1 * 1 * 6\.9[0-9] * \-*298\.[0-9] * \-*162\.[0-9] * \-*0*\.[0-9] * (0| )\.0 * (0| )\.0 * (0| )\.0" $log | wc -l`
CRIT2=`$GREP "1 * 2 * 7\.5[0-9] * \-*1166\.[0-9] * \-*15\.[0-9] * \-*0*\.[0-9] * (0| )\.0 * (0| )\.0 * (0| )\.0" $log | wc -l`
CRIT3=`$GREP "1 * 3 * 9\.2[0-9] * \-*116\.[0-9] * \-*0*\.[0-9] * \-*0*\.[0-9] * (0| )\.0 * (0| )\.0 * (0| )\.0" $log | wc -l`
CRIT4=`$GREP "1 * 4 * 9\.4[0-9] * \-*174\.[0-9] * \-15*\.[0-9] * \-*0*\.[0-9] * (0| )\.0 * (0| )\.0 * (0| )\.0" $log | wc -l`
CRIT5=`$GREP "1 * 5 * 12\.5[0-9] * \-*77\.[0-9] * \-*35\.[0-9] * \-*0*\.[0-9] * (0| )\.0 * (0| )\.0 * (0| )\.0" $log | wc -l`
TEST[7]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5`
CTRL[7]=5
ERROR[7]="TWO-PHOTON TRANSITION TENSOR NOT CORRECT"

# Two-photon transition probabilities
CRIT1=`$GREP "1 * 1 * 6\.9[0-9] * Linear * (0| )\.70[0-9](D|E)\+04 * (0| )\.38[0-9](D|E)\+04 * (0| )\.29[0-9](D|E)\+05 * ( |0)\.10.(D|E)\+04 * (0| )\.3[0-9]" $log | wc -l`
CRIT2=`$GREP "1 * 1 * 6\.9[0-9] * Circular * (0| )\.70[0-9](D|E)\+04 * (0| )\.38[0-9](D|E)\+04 * (0| )\.89[0-9](D|E)\+04 * ( |0)\.31.(D|E)\+03 * (0| )\.3[0-9]" $log | wc -l`
CRIT3=`$GREP "1 * 2 * 7\.5[0-9] * Linear * (0| )\.46[0-9](D|E)\+05 * (0| )\.45[0-9](D|E)\+05 * (0| )\.27[0-9](D|E)\+06 * ( |0)\.11.(D|E)\+05 * (0| )\.6[0-9]" $log | wc -l`
CRIT4=`$GREP "1 * 2 * 7\.5[0-9] * Circular * (0| )\.46[0-9](D|E)\+05 * (0| )\.45[0-9](D|E)\+05 * (0| )\.17[0-9](D|E)\+06 * ( |0)\.73.(D|E)\+04 * (0| )\.6[0-9]" $log | wc -l`
CRIT5=`$GREP "1 * 3 * 9\.2[0-9] * Linear * (0| )\.44[0-9](D|E)\+03 * (0| )\.45[0-9](D|E)\+03 * (0| )\.27[0-9](D|E)\+04 * ( |0)\.16.(D|E)\+03 * (0| )\.6[0-9]" $log | wc -l`
CRIT6=`$GREP "1 * 3 * 9\.2[0-9] * Circular * (0| )\.44[0-9](D|E)\+03 * (0| )\.45[0-9](D|E)\+03 * (0| )\.18[0-9](D|E)\+04 * ( |0)\.11.(D|E)\+03 * (0| )\.6[0-9]" $log | wc -l`
CRIT7=`$GREP "1 * 4 * 9\.4[0-9] * Linear * (0| )\.84[0-9](D|E)\+03 * (0| )\.10[0-9](D|E)\+04 * (0| )\.57[0-9](D|E)\+04 * ( |0)\.37.(D|E)\+03 * (0| )\.7[0-9]" $log | wc -l`
CRIT8=`$GREP "1 * 4 * 9\.4[0-9] * Circular * (0| )\.84[0-9](D|E)\+03 * (0| )\.10[0-9](D|E)\+04 * (0| )\.44[0-9](D|E)\+04 * ( |0)\.29.(D|E)\+03 * (0| )\.7[0-9]" $log | wc -l`
CRIT9=`$GREP "1 * 5 * 12\.5[0-9] * Linear * (0| )\.59[0-9](D|E)\+02 * (0| )\.24[0-9](D|E)\+03 * (0| )\.10[0-9](D|E)\+04 * ( |0)\.12.(D|E)\+03 * 1\.2[0-9]" $log | wc -l`
CRIT10=`$GREP "1 * 5 * 12\.5[0-9] * Circular * (0| )\.59[0-9](D|E)\+02 * (0| )\.24[0-9](D|E)\+03 * (0| )\.13[0-9](D|E)\+04 * ( |0)\.15.(D|E)\+03 * 1\.2[0-9]" $log | wc -l`
TEST[8]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ \
		$CRIT7 \+ $CRIT8 \+ $CRIT9 \+ $CRIT10`
CTRL[8]=10
ERROR[8]="TWO-PHOTON TRANSITION PROBABILITIES NOT CORRECT"

PASSED=1
for i in 1 2 4 5 6 7 8
do
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM
  exit 1
fi

%EOF%
#######################################################################
